package com.java.huxb.day01;

/**
 * @author huxb
 * @date 2020/2/26 0026 下午 3:56
 */
class  CreateThread implements  Runnable{
    private int count;

    public CreateThread(int count) {
        this.count = count;
    }

    @Override
    public void run() {
        while (count > 0) {

            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            sale();
        }
    }

    public synchronized void sale() {
       if (count > 0) {
           System.out.println(Thread.currentThread().getName() + "----" + (100 - count + 1));
           count--;
       }
    }
}
public class ThreadDemo02 {
    public static void main(String[] args) {
        CreateThread createThread = new CreateThread(100);
        Thread thread = new Thread(createThread);
        Thread thread2 = new Thread(createThread);
        thread.start();
        thread2.start();
    }


}
